package com.platform.wechat.controller;

import com.platform.wechat.common.JsonBean;
import com.platform.wechat.entity.Patient;
import com.platform.wechat.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author 嗷嗷嗷
 * @title: PatientConller
 * @projectName wechat114
 * @description: TODO
 * @date 2021/7/2812:54
 */
@RestController
@RequestMapping("patient")
public class PatientController {

    @Autowired
    private PatientService patientService;

    /**
     * 添加就诊人
     * @param patient
     * @return
     */
    @RequestMapping("insert")
    public JsonBean insert( Patient patient,HttpSession session){
        Object platformPhone1 = session.getAttribute("platformPhone");
        String phone = String.valueOf(platformPhone1);
        return patientService.insertPatient(patient,phone);
    }

    /**
     * 删除就诊人
     * @param patientId
     * @return
     */
    @PostMapping("delete")
    public JsonBean delete(Integer patientId){
        return patientService.deletePatient(patientId);
    }

    /**
     * 修改就诊人
     * @param patient
     * @return
     */
    @RequestMapping("update")
    public JsonBean update(Patient patient){
        //System.err.println(patient);
        return patientService.updatePatient(patient);
    }

    /**
     * 查询就诊人详细信息
     * @param patientId
     * @return
     */
    @PostMapping("selectBy")
    public JsonBean selectBy(Integer patientId){
        return patientService.selectBy(patientId);
    }

    /**
     * 查询所有就诊人
     * @return
     */
    @RequestMapping("select")
    public JsonBean select(HttpSession session){
        Object platformPhone1 = session.getAttribute("platformPhone");
        String phone = String.valueOf(platformPhone1);
        return patientService.selectPatient(phone);
    }

    /**
    * @Description: 根据身份证号码查询个人信息
    * @Param: [cardId]
    * @return: com.platform.wechat.common.JsonBean
    * @Author: YP
    * @Date: 2021/8/3
    * @Time: 20:26
    */
    @RequestMapping("selectByCardId")
    public JsonBean selectByCardId(String cardId){
        JsonBean jsonBean = patientService.selectByCardId(cardId);
        //System.err.println(jsonBean);
        return jsonBean;
    }

}
